home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 266_01 / printdev.c < prev    next >
C/C++ Source or Header  |  1990-07-13  |  4KB  |  134 lines

  1. /*                                                   File: PRINTDEV.C
  2.        Common code for dot-matrix printer drivers
  3.        Copyright 02 May 1990, Robert L. Patton, Jr.
  4.    Designed to be included and customized by a main driver that
  5.    has all the standard #include files and that defines HSPACE,
  6.    PRINTYPE and DX.
  7. */
  8. #define GETINT GetWord
  9. #define GETXY(A,B) A=DX(GETINT(Plot))+Xo;B=GETINT(Plot)+Yo;
  10. #define HBUMP1 HSPACE+3
  11. #define HBUMP2 HSPACE+5
  12.  
  13. main(ArgC,ArgV)
  14. int  ArgC;
  15. char *ArgV[];
  16. {
  17.   FILE *Plot;
  18.   static int  Command=0,Xp=0,Yp=0,Xo=0,Yo=0,Bold=0;
  19.   int  I,J,M,N,X,Y,X2,Y2,Shape,Pattern,Density,Hit,Gap;
  20.   unsigned Count=0;
  21.   #include "bitfont.h"
  22.  
  23.   LP_SetType (PRINTYPE);
  24.   if (ArgC > 1) Bold = 1;
  25.   Plot=fopen("PLOTCOM.DAT","rb");
  26.   NewImage();
  27.   while (Command<99)  {
  28.     Command=getc(Plot);
  29.     if(Command==EOF) Command=99;
  30.     if(++Count%10==0) putchar('+');
  31.     else              putchar('.');
  32.     if(Count%50==0)   putchar('\n');
  33.     switch (Command)
  34.     {
  35.       case   ON: GETXY(Xp,Yp)    /* Set pixel */
  36.                  Dot(Xp,Yp);
  37.                  break;
  38.  
  39.       case MARK: GETXY(X,Y)       /* Move and mark */
  40.                  Line(Xp,Yp,X,Y);
  41.                  Xp=X;Yp=Y;
  42.                  break;
  43.  
  44.       case MOVE: GETXY(Xp,Yp)    /* Move */
  45.                  break;
  46.  
  47.       case LTYP: SetLine (getc(Plot)); /* Set line type */
  48.                  break;
  49.  
  50.       case TXTH: ;                /* Font 1 horizontal */
  51.       case TXTV: GETXY(X,Y)       /* Font 1 vertical */
  52.                  while ((N=getc(Plot))!=0) {
  53.                   if(N<0x20) N=0x20;
  54.                   else if(N>0x5F) N-=0x20;
  55.                   N=Font1[N-0x20];
  56.                   for(J=0;J<5;J++)
  57.                     for(I=0;I<3;I++) {
  58.                       if(N&1) Dot(X+I,Y+J);
  59.                         N=N>>1;
  60.                     }
  61.                   if (Command==TXTH) X+=HBUMP1;
  62.                   else               Y-=7;
  63.                  }
  64.                  Xp=X;Yp=Y;
  65.                  break;
  66.  
  67.       case TX2H:                  /* Font 2 horizontal */
  68.       case TX2V: GETXY(X,Y)       /* Font 2 vertical */
  69.                  while ((N=getc(Plot))!=0) {
  70.                   if(N<0x20) N=0x20;
  71.                   N-=0x20;
  72.                   M=Font2[N][0];
  73.                   N=Font2[N][1];
  74.                   for (I=0;I<5;I++)
  75.                     for (J=0;J<3;J++) {
  76.                       if (M&1) Dot(X+I,Y+J);
  77.                       if (N&1) Dot(X+I,Y+J+3);
  78.                       M=M>>1;
  79.                       N=N>>1;
  80.                     }
  81.                     if (Command==TX2H) X+=HBUMP2;
  82.                     else               Y-=8;
  83.                   }
  84.                   Xp=X; Yp=Y;
  85.                   break;
  86.  
  87.       case SYMB: Shape=getc(Plot); /* Draw symmetrical symbol */
  88.                  for(J=1;J<3;J++)
  89.                    for(I=2;I>=0;I--) {
  90.                      if(Shape&1) {
  91.                        Dot(Xp+I,Yp+J);
  92.                        Dot(Xp-J,Yp+I);
  93.                        Dot(Xp-I,Yp-J);
  94.                        Dot(Xp+J,Yp-I);
  95.                      }
  96.                      Shape=Shape>>1;
  97.                    }
  98.                  if(Shape%2) Dot(Xp,Yp);
  99.                  break;
  100.  
  101.       case ORIG: Xo=GETINT(Plot); /* New origin */
  102.                  Yo=GETINT(Plot);
  103.                  break;
  104.  
  105.       case MRGN: LP_Margin(N=GETINT(Plot)); /* Set Margin */
  106.                  break;
  107.  
  108.       case HTYP: Pattern=GETINT(Plot);  /* Set hatch type */
  109.                  Density=GETINT(Plot);
  110.                  SetHatch (Pattern,Density);
  111.                  break;
  112.  
  113.       case FILL: GETXY(X,Y)    /* Hatch area */
  114.                  GETXY(X2,Y2)
  115.                  for (J=Y+1;J<Y2;J++) {
  116.                    HatchHow (J-Y,&Hit,&Gap);
  117.                    for (I=X+1;I<X2;I++)
  118.                      if (!((I-X+Hit)%Gap)) Dot(I,J);
  119.                      else                NoDot(I,J);
  120.                  }
  121.                  break;
  122.  
  123.       case CLOS: M=GETINT(Plot);   /* Print picture */
  124.                  N=GETINT(Plot);
  125.                  Draw(M,N,Bold);
  126.                  Xp=Yp=Xo=Yo=0;
  127.                  break;
  128.  
  129.       case  HUE: M=GETINT(Plot);   /* Absorb the color code */
  130.                  break;
  131.     }
  132.   }
  133. }
  134.